05.c - Automation-Scripts
Relevant source files
This page documents the bash automation scripts that listen for ntfy notifications and automatically clone customer repositories into private mirrors in the owner's GitHub account. The scripts serve as the execution layer of the automation pipeline, consuming events from the ntfy message broker and orchestrating git operations.
For information about the ntfy integration and notification payload format, see 5.1. For the conceptual overview of the cloning pipeline, see 5.2.
Script VariantsLink copied!
The codebase includes two script files with identical functionality:
| Script File | Purpose | Location |
|---|---|---|
ntfy-godeep-automation.sh | Primary automation script for local execution | scripts/ntfy-godeep-automation.sh L1-L152 |
ntfy-godeep-automation-remote.sh | Identical copy intended for remote deployment scenarios | scripts/ntfy-godeep-automation-remote.sh L1-L152 |
Both scripts contain identical code and can be used interchangeably. The separate files suggest a deployment strategy where one script runs on the owner's local machine while another could run on a remote server, but the implementation is identical.
Sources: scripts/ntfy-godeep-automation.sh L1-L152
scripts/ntfy-godeep-automation-remote.sh L1-L152
Script ArchitectureLink copied!
Configuration VariablesLink copied!
The scripts define three critical configuration constants at the top:
TOPIC="topic-XXXXXXXX"ADMIN_URL="https://www.godeep.wiki/api/admin/generate-token"CLONE_DIR="$HOME/godeep-clones"
| Variable | Purpose | Default Value |
|---|---|---|
TOPIC | ntfy.sh topic name for subscription | topic-XXXXXXXX |
ADMIN_URL | API endpoint for token generation | https://www.godeep.wiki/api/admin/generate-token |
CLONE_DIR | Local directory for repository clones | ~/godeep-clones |
The scripts also dynamically determine their location and project root:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"
This allows the script to locate the .env file regardless of the current working directory when executed.
Sources: scripts/ntfy-godeep-automation.sh L6-L13
Password ExtractionLink copied!
The script reads ADMIN_PASSWORD from the .env file located in the project root. This extraction happens at startup with validation:
Password Extraction Flow
The extraction command uses shell utilities to parse the .env file:
ADMIN_PASSWORD=$(grep "^ADMIN_PASSWORD=" "$ENV_FILE" | cut -d '=' -f2- | tr -d '"' | tr -d "'")
This command:
- Uses
grepto find lines starting withADMIN_PASSWORD= - Uses
cutto extract everything after the=sign - Uses
trto remove surrounding quotes (both single and double)
Sources: scripts/ntfy-godeep-automation.sh L15-L28
Execution FlowLink copied!
Main Event LoopLink copied!
The script runs an infinite loop that subscribes to the ntfy topic and processes each notification:
Sources: scripts/ntfy-godeep-automation.sh L39-L151
Notification DetectionLink copied!
The script uses pattern matching to identify GitHub installation notifications:
if echo "$title" | grep -q "GitHub Connected\|GitHub Installation"; then
This regex matches notification titles from the OAuth callback handler (app/api/auth/github/callback/route.ts L87-L93
). When matched, the script enters the installation processing workflow.
Sources: scripts/ntfy-godeep-automation.sh L49
Installation ID ExtractionLink copied!
The installation ID is extracted from the notification message using grep with regex:
installation_id=$(echo "$message" | grep -o 'Installation ID: [0-9]*' | grep -o '[0-9]*$')
This extraction targets the message format: "Installation ID: <number>" which is sent by the callback handler.
Sources: scripts/ntfy-godeep-automation.sh L53
Token Generation and API IntegrationLink copied!
Admin API CallLink copied!
The script calls the admin token generation API with the extracted installation ID:
API Request Structure
The curl command constructs a POST request:
response=$(curl -s -X POST "$ADMIN_URL" \ -H "Content-Type: application/json" \ -d "{\"installationId\":\"$installation_id\",\"password\":\"$ADMIN_PASSWORD\"}")
Sources: scripts/ntfy-godeep-automation.sh L62-L65
Response ParsingLink copied!
The script extracts four key fields from the API response using jq:
| Field | jq Expression | Fallback |
|---|---|---|
| Access token | .token | empty |
| Repository full name | .repositories[0].full_name | empty |
| Repository name | .repositories[0].name | empty |
| Customer email | .user.email // .user.username | empty |
The fallback chain for customer identification (email // .user.username) ensures the script can handle cases where email is not available.
Sources: scripts/ntfy-godeep-automation.sh L68-L71
Repository Cloning PipelineLink copied!
Repository Name FormattingLink copied!
The script generates a formatted repository name that includes the customer identifier:
email_prefix=$(echo "$customer_email" | sed 's/@/_/g; s/\./_/g' | tr '[:upper:]' '[:lower:]')formatted_repo_name="${email_prefix}-${repo_name}"
This transformation:
- Replaces
@symbols with underscores - Replaces
.symbols with underscores - Converts to lowercase
- Concatenates with the original repository name
Example: john.doe@example.com + my-repo → john_doe_example_com-my-repo
Sources: scripts/ntfy-godeep-automation.sh L79-L84
Git Clone OperationLink copied!
The script clones the customer's repository using token authentication:
git clone "https://x-access-token:${token}@github.com/${repo_full_name}.git" "$clone_path"
The x-access-token authentication scheme is GitHub's standard method for using personal access tokens or installation access tokens with HTTPS git operations.
Sources: scripts/ntfy-godeep-automation.sh L90
Repository Re-initializationLink copied!
Git History Removal and Re-commitLink copied!
After successful cloning, the script creates a clean repository with a new commit history:
Re-initialization Steps
This process ensures that:
- The customer's commit history is not retained
- The owner's private repository has a single, clean commit
- The customer email is documented in the commit message for tracking
Sources: scripts/ntfy-godeep-automation.sh L99-L103
Private Repository CreationLink copied!
GitHub CLI IntegrationLink copied!
The script uses the GitHub CLI (gh) to create a private repository and push the re-initialized code:
gh repo create "klaudioz/$formatted_repo_name" --private --source=. --push
This single command:
- Creates a new private repository in the
klaudiozaccount - Adds it as a remote to the local repository
- Pushes all commits to the new remote
Repository Creation Flow
Sources: scripts/ntfy-godeep-automation.sh L106
Cleanup and Resource ManagementLink copied!
Local Clone DeletionLink copied!
After successful or failed repository creation, the script deletes the local clone to conserve disk space:
cd - > /dev/nullrm -rf "$clone_path"
The cd - command returns to the previous directory before deletion, preventing the script from attempting to delete the current working directory.
The cleanup happens in both success and failure paths:
- Success path: scripts/ntfy-godeep-automation.sh L110-L115
- Failure path: scripts/ntfy-godeep-automation.sh L122-L127
This ensures disk space is freed regardless of outcome.
Sources: scripts/ntfy-godeep-automation.sh L110-L127
macOS Notification SystemLink copied!
The scripts use AppleScript via osascript to display native macOS notifications at each stage of processing.
Notification PointsLink copied!
| Stage | Notification Content | Code Location |
|---|---|---|
| Installation detected | "Processing Installation ID: {id}" | scripts/ntfy-godeep-automation.sh L59 |
| Clone complete | "Repository cloned to {path}" | scripts/ntfy-godeep-automation.sh L94 |
| Repo created successfully | "Repository created: klaudioz/{name}" | scripts/ntfy-godeep-automation.sh L117 |
| Repo creation failed | "Failed to create repo: {name}" | scripts/ntfy-godeep-automation.sh L129 |
| Clone failed | "Clone failed for {repo}" | scripts/ntfy-godeep-automation.sh L134 |
| Token generation failed | "Failed to process Installation ID: {id}" | scripts/ntfy-godeep-automation.sh L139 |
| Other notifications | "{message}" with title "{title}" | scripts/ntfy-godeep-automation.sh L147 |
AppleScript Command StructureLink copied!
All notifications use the same AppleScript pattern:
osascript -e "display notification \"<message>\" with title \"<title>\""
The -e flag allows inline AppleScript execution without requiring a separate file.
Sources: scripts/ntfy-godeep-automation.sh L59-L147
Error HandlingLink copied!
Validation ChecksLink copied!
The script implements several validation checkpoints throughout execution:
Error Detection Points
Fatal vs Non-Fatal ErrorsLink copied!
The script distinguishes between fatal errors (exit immediately) and non-fatal errors (log and continue):
Fatal Errors (exit script):
.envfile not found: scripts/ntfy-godeep-automation.sh L17-L20ADMIN_PASSWORDnot found in.env: scripts/ntfy-godeep-automation.sh L25-L28
Non-Fatal Errors (log and continue to next notification):
- Installation ID extraction failure: scripts/ntfy-godeep-automation.sh L141-L143
- Token generation failure: scripts/ntfy-godeep-automation.sh L136-L140
- Clone failure: scripts/ntfy-godeep-automation.sh L132-L135
- Repository creation failure: scripts/ntfy-godeep-automation.sh L118-L130
Non-fatal errors allow the script to continue processing future notifications even if one customer's installation fails.
Sources: scripts/ntfy-godeep-automation.sh L17-L143
Setup RequirementsLink copied!
PrerequisitesLink copied!
The script requires the following command-line tools:
| Tool | Purpose | Installation Check |
|---|---|---|
ntfy | Subscribe to ntfy.sh topics | which ntfy |
jq | Parse JSON responses | which jq |
git | Clone repositories | which git |
gh | GitHub CLI for repo creation | which gh |
curl | HTTP requests to admin API | which curl |
osascript | macOS notifications | Built into macOS |
Environment ConfigurationLink copied!
The script expects a .env file in the project root containing:
ADMIN_PASSWORD=<your-admin-password>
This password must match the ADMIN_PASSWORD environment variable configured in the Vercel deployment.
Sources: scripts/README.md L9-L80
Execution ModesLink copied!
Foreground ExecutionLink copied!
Run the script in the foreground to see real-time output:
./scripts/ntfy-godeep-automation.sh
Stop with Ctrl+C.
Background ExecutionLink copied!
Run the script as a background process with logging:
nohup ./scripts/ntfy-godeep-automation.sh > ~/ntfy-godeep.log 2>&1 &
This command:
nohup: Prevents termination when terminal closes> ~/ntfy-godeep.log: Redirects stdout to log file2>&1: Redirects stderr to stdout (same log file)&: Runs in background
Process ManagementLink copied!
| Task | Command |
|---|---|
| Stop background script | pkill -f ntfy-godeep-automation |
| View logs | tail -f ~/ntfy-godeep.log |
| Check if running | ps aux | grep ntfy-godeep-automation |
Sources: scripts/README.md L15-L63
TroubleshootingLink copied!
Common IssuesLink copied!
Authentication Failures
Symptom: API returns 401 or token validation fails
Causes:
- Password mismatch between
.envand Vercel environment variables - API endpoint not deployed with latest changes
Resolution:
- Verify
.envpassword matches VercelADMIN_PASSWORD - Check Vercel deployment logs for API errors
Clone Failures
Symptom: git clone command fails
Causes:
- Token expired (1-hour GitHub limitation)
- Network connectivity issues
- GitHub App permissions incorrect
Resolution:
- Check token generation timestamp in logs
- Verify network connectivity to GitHub
- Verify GitHub App has "Contents: Read-only" permission
Script Won't Start
Symptom: Script exits immediately after launch
Causes:
.envfile not foundADMIN_PASSWORDnot set in.env- Required tools not installed
Resolution:
- Verify
.envexists in project root - Check
ADMIN_PASSWORDis defined in.env - Run
which ntfy,which jq,which ghto verify tool installation
Sources: scripts/README.md L65-L80
Workflow SummaryLink copied!
The complete automation workflow from notification to repository creation:
This workflow executes automatically for each GitHub installation notification, requiring no manual intervention from the owner until the manual documentation generation step.
Sources: scripts/ntfy-godeep-automation.sh L39-L151
Refresh this wiki
Last indexed: 23 November 2025 (922b35)
On this page
- Automation Scripts
- Script Variants
- Script Architecture
- Configuration Variables
- Password Extraction
- Execution Flow
- Main Event Loop
- Notification Detection
- Installation ID Extraction
- Token Generation and API Integration
- Admin API Call
- Response Parsing
- Repository Cloning Pipeline
- Repository Name Formatting
- Git Clone Operation
- Repository Re-initialization
- Git History Removal and Re-commit
- Private Repository Creation
- GitHub CLI Integration
- Cleanup and Resource Management
- Local Clone Deletion
- macOS Notification System
- Notification Points
- AppleScript Command Structure
- Error Handling
- Validation Checks
- Fatal vs Non-Fatal Errors
- Setup Requirements
- Prerequisites
- Environment Configuration
- Execution Modes
- Foreground Execution
- Background Execution
- Process Management
- Troubleshooting
- Common Issues
- Workflow Summary
Ask Devin about godeep.wiki-jb
Syntax error in text
mermaid version 11.4.1